package com.shuoyue.ycgk.ui.mine.coupon;

import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.entity.Coupon;
import com.shuoyue.ycgk.entity.Mok;
import com.shuoyue.ycgk.entity.QuestionParent;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface CouponContract {
    interface View extends BaseView {
        void getCouponList(List<Coupon> list);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getCoupons(Integer type, Integer statue) {
            getCoupons(type, statue, null, null);
        }

        /**
         * @param type   //0：失效，1：有效
         * @param statue //1：未使用，2：已使用
         */
        public void getCoupons(Integer type, Integer statue, Integer useType, Integer subjectTypeId) {
            apply(model.getCoupons(type, statue, useType, subjectTypeId))
                    .subscribe(new ApiSubscriber<Optional<List<Coupon>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<Coupon>> lessonProcessOptional) {
                            super.onNext(lessonProcessOptional);
                            mView.getCouponList(lessonProcessOptional.getIncludeNull());
                        }

                    });
        }
    }

    class Model {
        Observable<BaseResult<List<Coupon>>> getCoupons(Integer type, Integer statue, Integer useType, Integer subjectTypeId) {
            return RetrofitClient.getInstance().getApi().getCoupons(type, statue, useType, subjectTypeId);
        }

    }
}
